package mvp.com.bbc.ui.fragment;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import mvp.com.bbc.R;
import mvp.com.bbc.bean.ArtBeans;

/**
 * Created by ${cbf} on 2017/10/9.
 */

public class ArtListAdapter extends RecyclerView.Adapter<ArtListAdapter.Vholder> {
    private List<ArtBeans.ArtBean> mArtBeen;
    private Context mContext;
    private String type;

    public ArtListAdapter(Context context, String type) {
        this.mContext = context;
        this.type = type;
        mArtBeen = new ArrayList<>();
    }

    public void initData(List<ArtBeans.ArtBean> art) {
        this.mArtBeen = art;
        notifyDataSetChanged();
    }

    public void addData(List<ArtBeans.ArtBean> art) {
        this.mArtBeen.addAll(art);
        notifyDataSetChanged();
    }

    @Override
    public ArtListAdapter.Vholder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_item_art, parent, false);
        return new Vholder(view);
    }

    @Override
    public void onBindViewHolder(ArtListAdapter.Vholder holder, int position) {
        ArtBeans.ArtBean artBean = mArtBeen.get(position);
        Glide.with(mContext).load(artBean.getIcon()).error(R.drawable.fail).into(holder.mIvHead);
        holder.mTvName.setText(artBean.getName());
        holder.mTvTime.setText(artBean.getCreattime().getTime());
        holder.mTvAttenton.setText(artBean.getCon() + "");
        holder.mTvCount.setText(artBean.getLn() + "");

    }

    @Override
    public int getItemCount() {
        return mArtBeen == null ? 0 : mArtBeen.size();
    }


    public class Vholder extends RecyclerView.ViewHolder {

        private final ImageView mIvHead;
        private final TextView mTvName;
        private final TextView mTvTime;
        private final TextView mTvCount;
        private final TextView mTvAttenton;
        private final Button mClick;
        private final Button mAttention;

        public Vholder(View itemView) {
            super(itemView);
            mIvHead = (ImageView) itemView.findViewById(R.id.iv_head_art);
            mTvName = (TextView) itemView.findViewById(R.id.tv_name_art);
            mTvTime = (TextView) itemView.findViewById(R.id.tv_time_art);
            mTvCount = (TextView) itemView.findViewById(R.id.tv_art_click_count);
            mTvAttenton = (TextView) itemView.findViewById(R.id.tv_art_click_attention);
            mClick = (Button) itemView.findViewById(R.id.btn_art_click);
            mAttention = (Button) itemView.findViewById(R.id.btn_art_attention);
        }
    }
}
